﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TOrderID = System.Int32;
using TConsumptionRecdID = System.Int64;
using TConsumptionTreeID = System.Int32;

namespace DatabaseAgency
{
    public class EmParentTreeNode
    {
        public EmParentTreeNode()
        {
            iFatherId = -1;
            iSelfId = -1;
        }
        public EmParentTreeNode(int aFatherId, int aSelfId)
        {
            iFatherId = aFatherId;
            iSelfId = aSelfId;
        }
        public int iFatherId;
        public int iSelfId;
    }

    public class ConsumptionTree
    {
        public ConsumptionTree()
        {
            iFather = -1;
            iDeviceId = -1;
        }
        public ConsumptionTree(int aFather, int aCategoryId)
        {
            iFather = aFather;
            iDeviceId = aCategoryId;
        }
        public int iFather;//-1是根目录
        public int iDeviceId;   //只有叶子是真正的表
        public String iCategoryName;
        public String iUnit;
    }

    public class EmConsumptionRecd
    {
        public EmConsumptionRecd()
        {
            iId = 0;
            iDeviceId = 0;
            iTime = DateTime.Now;
            iParam = 0;
            iUnit = 0;
        }
        public int iId;
        public int iDeviceId;
        public string iDeviceName; //待定
        public DateTime iTime;
        public double iParam;   //抄表的数据
        public double iUnit;    //单价
    }

    public class EmRepairAreaTreeNode
    {
        public int iFather;
        public string iAreaStr;//"区域#code"
    }

    // public ConsumptionAllClassRecord
    // {
    // CDate iDate,
    // List<ConsumptionSubClassRecord> iSubClassRecordList,
    // }
    /// <summary>
    /// 一个报修单在数据库中的字段
    /// </summary>
    [Serializable]
    public class EmRepairOrderInfo
    {
        //项目编号
        public TOrderID iId { get; set; }
		
		//当前状态下的处理人
        public string iEnginnerrName { get; set; }
		
        //等级
        public int iLevel { get; set; }
		
		//当前状态
        public TOrderStatus iCurStatus { get; set; }

        ///流转次数
        public int iRepaireTimes { get; set; }

		//状态列表
        public List<TOrderStatus> iStatusList { get; set; }
        public List<DateTime> iStatusTimeList { get; set; }

        public string iCreator { get; set; }

		//维修地点
		//分号分隔区域
        public string iLocation { get; set; }

        //维修类型
        public string iRepairObject { get; set; }

        //维修项目
        public string iRepairContent { get; set; }

        //耗材
        public string iConsumables { get; set; }

        //备注, 对设备损坏的描述
        public string iNotes { get; set; }
    }

    [Serializable]
    public class EmRepairOrderStatusInfo
    {
        //public TOrderID iGuid;
        public int iRePassTimes;
        public string iUserName;
        public TOrderStatus iStatus;
        public DateTime iTime;
        public int iLevel;
        public string aNotes;
    }

    public class ErrorHelper
    {
        private static Dictionary<int, string> _ErrMsgDict = null;
        static ErrorHelper()
        {
            _ErrMsgDict = new Dictionary<int, string>();

            _ErrMsgDict[-1] = "用户名或密码错误";
            _ErrMsgDict[-2] = "连接服务器失败";
            _ErrMsgDict[-3] = "酒店信息已更改, 请重新登录";
        }

        public static string ErrCode2Str(int code)
        {
            return _ErrMsgDict[code];
        }
    }

    public enum TOrderStatus: int
    {
        EUnKnown = 0,
        EUnAccept = 1,
        ERepairing = 2,
        EHold = 3,
        ERepairFail = 4,
        ERepaired = 5
    }

    public enum UserType
    {
        HotelTerm,
        EngineerDept
    }

    /// <summary>
    /// 酒店下单终端需要从服务器获取的信息
    /// </summary>
    [Serializable]
    public class HotelInfo
    {
        //用户姓名
        public string UserName;

        //用户所在的部门
        public string UserDept;

        public List<string> DepartmentList;

        //酒店的地点信息(一个森林)
        public List<LocationInfo> HotelLoc;
        
        //报修等级信息
        public List<LevelInfo> Level;

        //状态信息
        public List<StateInfo> State;

        //工人信息
        public List<string> Workers;

        //耗材列表
        public List<string> Consumables;

        //能耗种类
        public List<ConsumptionTypeInfo> ConsumptionType;

        public HotelInfo()
        {
            HotelLoc = new List<LocationInfo>();
            Level = new List<LevelInfo>();
            State = new List<StateInfo>();
            Workers = new List<string>();
        }
    }

    /// <summary>
    /// 酒店的位置信息
    /// </summary>
    [Serializable]
    public class LocationInfo
    {
        //位置的名称, 例如客房301
        public string LocName { get; set; }

        //位置的代码名称, 如rsa301
        public string LocCode { get; set; }

        //双亲表示法中, 它的双亲的下标
        public int ParentId;

        //报修类型列表, 里面包含了报修项目
        public List<ObjectInfo> RepairObjList;

        //它的子节点
        public List<LocationInfo> ChildrenLoc = new List<LocationInfo>();

        public LocationInfo(EmRepairAreaTreeNode node)
        {
            string[] locStrList = node.iAreaStr.Split('#');
            LocName = locStrList[0];
            LocCode = locStrList[1];
            ParentId = node.iFather;
            RepairObjList = null;
        }
    }

    /// <summary>
    /// 能耗的种类
    /// </summary>
    public class ConsumptionTypeInfo
    {
        public int FatherId;     //-1是根目录
        public int DeviceId;   //当前能耗表的Id. 只有叶子是真正的表
        public String CategoryName; //能耗表的名字
        public String Unit;         //能耗的单位
        public List<ConsumptionTypeInfo> ChildrenConType = new List<ConsumptionTypeInfo>();

        public ConsumptionTypeInfo(ConsumptionTree node)
        {
            FatherId = node.iFather;
            DeviceId = node.iDeviceId;
            CategoryName = node.iCategoryName;
            Unit = node.iUnit;
        }
    }

    /// <summary>
    /// 报修类型
    /// </summary>
    [Serializable]
    public class ObjectInfo
    {
        //报修类型
        public string ObjectName { get; set; }

        //类型代码
        public string ObjectCode { get; set; }

        //报修项目列表
        public List<ContentInfo> Contents = new List<ContentInfo>();
    }

    /// <summary>
    /// 报修项目
    /// </summary>
    [Serializable]
    public struct ContentInfo
    {
        //报修项目
        public string ContentName { get; set; }

        //项目代码
        public string ContentCode { get; set; }
    }

    /// <summary>
    /// 有哪些优先等级
    /// </summary>
    [Serializable]
    public struct LevelInfo
    {
        //等级名称
        public string LevelName { get; set; }

        //等级代码
        public int LevelCode { get; set; }
    }

    /// <summary>
    /// 有哪些状态
    /// </summary>
    [Serializable]
    public struct StateInfo
    {
        //等级名称
        public string StateName { get; set; }

        //等级代码
        public TOrderStatus StateCode { get; set; }

        //可以跳转到哪些状态
        public List<TOrderStatus> NextStateList { get; set; }
    }

    public class EmGuid 
    {
        public Int64 iLowId;
        public Int64 iHightId;
        public EmGuid()
        {
            iLowId = 0;
            iHightId = 0;
        }
        public void SetGuid(byte[] aGuid)
        {
            if (aGuid.Length != 8) return;

            Int64 mask = 0xFF;
            int index = 0;
            iLowId = 0;
            iHightId = 0;
            for (int i = 0; i < 4; ++i)
            {
                index++;
                iLowId += (mask << 8) & (((Int64)aGuid[i]) << (8 * index));
            }

            mask = 0xFF;
            index = 0;
            for (int i = 4; i < 8; ++i)
            {
                index++;
                iHightId += (mask << 8) & (((Int64)aGuid[i]) << (8 * index));
            }
        }
        /*
        public static bool operator ==(EmGuid aGuid1, EmGuid aGuid2)
        {
            return (aGuid1.iLowId == aGuid2.iLowId && aGuid1.iHightId == aGuid2.iHightId);
        }

        public static bool operator !=(EmGuid aGuid1, EmGuid aGuid2)
        {
            return (aGuid1.iLowId != aGuid2.iLowId || aGuid1.iHightId != aGuid2.iHightId);
        }
         */
    }
}
